# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libwpd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.10.3
pkgrel=2
pkgdesc="Library for Importing WordPerfect (tm) Documents (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://libwpd.sourceforge.io/"
msys2_references=(
  "cpe: cpe:/a:libwpd:libwpd"
  "cpe: cpe:/a:libwpd:libwpd_library"
  "cpe: cpe:/a:libwpd_project:libwpd"
)
license=('spdx:LGPL-2.1-or-later OR MPL-2.0')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-boost"
)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-librevenge"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=(!buildflags)
source=("https://downloads.sourceforge.net/project/${_realname}/${_realname}/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz"
        fix-condition.patch
        fix-var-sizes.patch)
sha256sums=('2465b0b662fdc5d4e3bebcdc9a79027713fb629ca2bff04a3c9251fdec42dd09'
            'bc596c1982365d5ee5eb659521e9343fcb7caee103bd5673f181df9a42aa9970'
            '125e7ea0b17b42bb41dbdc35c3072e40fa6a03e24f11f871620b261199d7cd4f')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/fix-condition.patch
  patch -p1 -i "${srcdir}"/fix-var-sizes.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}/build-${MSYSTEM}"

  export lt_cv_deplibs_check_method='pass_all'

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --without-docs \
    --disable-werror \
    --enable-silent-rules

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
